package com.nf.health.app.mine.activity;
import android.os.Bundle;
import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.adapter.BillAdapter;
import com.nf.health.app.customview.DragListView;
import com.nf.health.app.models.BillVo;
import com.nf.health.app.utils.ViewUtil;
import java.util.ArrayList;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
/**
 * 积分详情页&钱包消费页
 * Created by windoes on 2016/3/21.
 */
public class BillActivity extends BaseActivity {

    private List<BillVo> contentList = new ArrayList<BillVo>();
    String flag;
    List<BillVo> mlist;
    @Bind(R.id.bill_listview)//列表
            DragListView billListview;
    private BillAdapter billAdapter;

    int page=1,pagesize=20;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_bill);

        ButterKnife.bind(this);

        billListview.setRefreshableAndLoadMoreable(true, true);
        billListview.setOnRefreshAndLoadMoreListener(new DragListView.onRefreshAndLoadMoreListener() {
            @Override
            public void onRefresh() {
                page = 1;
                initData("refresh");
            }
            @Override
            public void onLoadMore() {
                page++;
                initData("more");
            }
        });
    }
    @Override
    public void handleActionSuccess(String actionName, Object object) {

        if("refresh".equals(actionName)){

            billListview.completeRefresh();
            mlist = (List<BillVo>) object;
            contentList.clear();
            contentList.addAll(mlist);

            billAdapter = new BillAdapter(this, mlist);
            billListview.setAdapter(billAdapter);


        }else if("more".equals(actionName)) {
            billListview.completeLoadMore();
            mlist = (List<BillVo>) object;
            if (mlist.size() == 0) {
                showToast("没有更多数据");
            } else {
                contentList.addAll(mlist);
                billAdapter.notifyDataSetChanged();
            }
        }
    }
    protected void onResume() {
        super.onResume();
        initData("refresh");
    }

    private void initData(String flag1) {

        flag = getIntent().getStringExtra("bill");

        if (flag.equals("wallet")) {//钱包变动详情
            ViewUtil.setText(this, R.id.titlebar_title_tv, "账单详情");
            billAdapter = new BillAdapter(this, mlist);
            billListview.setAdapter(billAdapter);
        } else if (flag.equals("integration")) {//积分详情
            provider.requestIntergrationHostory(page + "", pagesize + "", flag1);
            ViewUtil.setText(this, R.id.titlebar_title_tv, "积分详情");
        }
    }
}
